# -*- coding: utf-8 -*-

import os
from random import Random

part_length = 10
total_length = 200

add_q = 50
del_q = 0

shuffle_flag = False
unique_flag = True
sort_flag = False

def nrToSym(nr):
    if nr==0:
        return 'A'
    if nr==1:
        return 'C'
    if nr==2:
        return 'G'
    if nr==3:
        return 'T'

def uniq(list):
    u = {}
    for x in list:
        u[x]=1
    return u.keys()

dna = []
parts = []
rand = Random()

for i in range(total_length):
    dna.append(rand.randint(0,3))
		
dna = map(nrToSym,dna)

file = open("original.txt",'w')
file.write("".join(dna))
file.close()

for i in range(part_length,total_length+1):
    dna_part = dna[i-part_length:i]
    parts.append("".join(dna_part))

#duplikaty
if unique_flag:
    parts = uniq(parts)

#błędy pozytywne
if add_q > 0:
    parts_q = len(parts)
    new_parts = []
    new_one = parts[0]
    for i in xrange(add_q):
        while parts.__contains__(new_one) or new_parts.__contains__(new_one):
			a = parts[rand.randint(0,parts_q-1)]
			b = parts[rand.randint(0,parts_q-1)]
			while a==b:
				b = parts[rand.randint(0,parts_q-1)]
			cut = rand.randint(1,part_length-1)
			new_one = a[0:cut]+b[cut:part_length]
        new_parts.append(new_one)

#błędy negatywne
if del_q > 0:
    parts_q = len(parts)
    if del_q > parts_q:
        del_q = parts_q
    for i in xrange(del_q):
        parts.pop(rand.randint(0,len(parts)-1))
        
parts.extend(new_parts)

if shuffle_flag:
    rand.shuffle(parts)

if sort_flag:
    parts.sort()

path = str(total_length)+"-"+str(add_q)+"-"+str(del_q)+".txt"

file = open(path, 'w');
	
#file = open("seq.txt",'w')
file.write("\n".join(parts))
file.close()